{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "77442a83-a77e-4658-8802-aa9e10c83a76",
   "metadata": {},
   "outputs": [],
   "source": [
    "# imports\n",
    "import os\n",
    "from dotenv import load_dotenv\n",
    "from openai import OpenAI\n",
    "import anthropic\n",
    "from IPython.display import Markdown, display, update_display\n",
    "import google.generativeai\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "43dd50c6-2272-4f30-be95-0f8a715c1cc6",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Load environment variables in a file called .env\n",
    "# Print the key prefixes to help with any debugging\n",
    "\n",
    "load_dotenv(override=True)\n",
    "openai_api_key = os.getenv('OPENAI_API_KEY')\n",
    "anthropic_api_key = os.getenv('ANTHROPIC_API_KEY')\n",
    "google_api_key = os.getenv('GOOGLE_API_KEY')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cf744c45-b880-4d35-ae0e-8d74aaf82f8e",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "# Connect to OpenAI, Anthropic\n",
    "\n",
    "openai = OpenAI()\n",
    "\n",
    "claude = anthropic.Anthropic()\n",
    "\n",
    "# This is the set up code for Gemini\n",
    "# Having problems with Google Gemini setup? Then just ignore this cell; when we use Gemini, I'll give you an alternative that bypasses this library altogether\n",
    "\n",
    "google.generativeai.configure()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d33f4de7-b31e-4ef1-aa36-aa88f3156515",
   "metadata": {},
   "source": [
    "### Setup: Round robbin panel of night city representatives discussing Dogtown's independence."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "17f62aae-0b85-40b5-949a-1e684730d962",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "gpt_model = \"gpt-4.1-mini\"\n",
    "claude_model = \"claude-3-5-haiku-latest\"\n",
    "gemini_model = \"gemini-2.5-flash\"\n",
    "\n",
    "gpt_system = \"You are a chatbot version of a Cyberpunk 2077 StreetKid. Taking part in a round robbin panel comprised of a Corpo and a Nomad, discussing the impact of dogtown's current 'independence'. You are first in the panel. Try not to repeat yourself and respond to comments from each panel participant.\"\n",
    "\n",
    "claude_system = \"You are a chatbot version of Cyberpunk 2077 Corpo. Taking part in a round robbin panel, comprised of a Streetkid and a Nomad, discussing the impact of dogtown's current 'independence'. You are second in the panel. Try not to repeat yourself and respond to comments from each panel participant.\"\n",
    "\n",
    "gemini_system = \"You are a chatbot verion of Cyberpunk 2077 Nomad. Taking part in a round robbin panel, comprised of a Corpo and a Streetkid, discussing the impact of dogtown's current 'independence'. You are last in the panel. Try not to repeat yourself and respond to comments from each panel participant.\"\n",
    "\n",
    "gemini_messages = [\"Thanks for having me.\"]\n",
    "gpt_messages = [\"Howdy!\"]\n",
    "claude_messages = [\"Hi.\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "46cb6b7f-d9ee-445b-92b1-12dd0820c792",
   "metadata": {},
   "outputs": [],
   "source": [
    "def call_gpt(): #Streetkid\n",
    "    messages = [{\"role\": \"system\", \"content\": gpt_system}]\n",
    "    for gpt, claude, gemini in zip(gpt_messages, claude_messages, gemini_messages):\n",
    "        messages.append({\"role\": \"assistant\", \"content\": gpt})\n",
    "        messages.append({\"role\": \"user\", \"content\": claude})\n",
    "        messages.append({\"role\": \"user\", \"content\": gemini})\n",
    "    completion = openai.chat.completions.create(\n",
    "        model=gpt_model,\n",
    "        messages=messages\n",
    "    )\n",
    "    return completion.choices[0].message.content\n",
    "\n",
    "def call_claude(): #Corpo\n",
    "    messages = []\n",
    "    for gpt, claude_message, gemini in zip(gpt_messages, claude_messages, gemini_messages):\n",
    "        messages.append({\"role\": \"user\", \"content\": gpt})\n",
    "        messages.append({\"role\": \"user\", \"content\": gemini})\n",
    "        messages.append({\"role\": \"assistant\", \"content\": claude_message})\n",
    "    messages.append({\"role\": \"user\", \"content\": gpt_messages[-1]})\n",
    "    message = claude.messages.create(\n",
    "        model=claude_model,\n",
    "        system=claude_system,\n",
    "        messages=messages,\n",
    "        max_tokens=750\n",
    "    )\n",
    "    return message.content[0].text\n",
    "\n",
    "\n",
    "def call_gemini(): #Nomad\n",
    "    messages = [{\"role\": \"system\", \"content\": gemini_system}]\n",
    "    for gpt, claude_message, gemini in zip(gpt_messages, claude_messages, gemini_messages):\n",
    "        messages.append({\"role\": \"user\", \"content\": gpt})\n",
    "        messages.append({\"role\": \"user\", \"content\": claude_message})\n",
    "        messages.append({\"role\": \"assistant\", \"content\": gemini})\n",
    "    messages.append({\"role\": \"user\", \"content\": claude_messages[-1]})\n",
    "    gemini_via_openai_client = OpenAI(\n",
    "        api_key=google_api_key, \n",
    "        base_url=\"https://generativelanguage.googleapis.com/v1beta/openai/\"\n",
    "    )\n",
    "    response = gemini_via_openai_client.chat.completions.create(\n",
    "        model=\"gemini-2.5-flash\",\n",
    "        messages=messages\n",
    "    )\n",
    "    return response.choices[0].message.content"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9b4f2ec3-3a6c-4259-ac25-d4047be89bb5",
   "metadata": {
    "editable": true,
    "slideshow": {
     "slide_type": ""
    },
    "tags": []
   },
   "outputs": [],
   "source": [
    "print(f\"Streetkid:\\n{gpt_messages[0]}\\n\")\n",
    "print(f\"Corpo:\\n{claude_messages[0]}\\n\")\n",
    "print(f\"Nomad:\\n{gemini_messages[0]}\\n\")\n",
    "\n",
    "for i in range(3):\n",
    "    gpt_next = call_gpt()\n",
    "    print(f\"Streetkid:\\n{gpt_next}\\n\")\n",
    "    gpt_messages.append(gpt_next)\n",
    "    \n",
    "    claude_next = call_claude()\n",
    "    print(f\"Corpo:\\n{claude_next}\\n\")\n",
    "    claude_messages.append(claude_next)\n",
    "\n",
    "    gemini_next = call_gemini()\n",
    "    print(f\"Nomad:\\n{gemini_next}\\n\")\n",
    "    gemini_messages.append(gemini_next)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d2578fc5-0069-4776-881c-797718896fdc",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
